#include "insertSort.h"
#include "shellSort.h"
#include "heapSort.h"
#include "mergeSort.h"
#include "quickSort.h"
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include "quickSelect.h"
typedef enum
{
    SortTypeInsert,
    SortTypeShell,
    SortTypeHeap,
    SortTypeMerge,
    SortTypeQuick,
    SortTypeQuickSelect,
} SortType;

int main(int argc, char **argv)
{
    int i = 0;
    if (argc < 2 || strcmp(argv[1], "--help") == 0)
    {
        printf("%s: sortType\n0. insertSort\n1. shellSort\n2. HeapSort\n3. MergeSort\n"
               "4. QuickSort\n5. QuickSelect\n",
               argv[0]);
        exit(EXIT_SUCCESS);
    }

    int eleList[] = {32, 2, 35, 12, 4, 77, 21, 33, 425, 8};
    int num = sizeof(eleList) / sizeof(int);

    printf("We will sort the array: \n[");
    for (i = 0; i < num; i++)
    {
        if (i == 0)
            printf("%d", eleList[0]);
        else
            printf(",%d", eleList[i]);
    }
    printf("]\n");

    switch (atoi(argv[1]))
    {
    case SortTypeInsert:
        InsertionSort(eleList, num);
        break;
    case SortTypeShell:
        ShellSort(eleList, num);
        break;
    case SortTypeHeap:
        HeapSort(eleList, num);
        break;
    case SortTypeMerge:
        MergeSort(eleList, num);
        break;
    case SortTypeQuick:
        QuickSort(eleList, num);
        break;
    case SortTypeQuickSelect:
        printf("the %dth num is: %d\n", 5, QuickSelect(eleList, 5, num));
        break;
    default:
        printf("unknown type: %d\n", atoi(argv[1]));
        goto _exit;
    }

    printf("After sort, the array is:\n[");
    for (i = 0; i < num; i++)
    {
        if (i == 0)
            printf("%d", eleList[0]);
        else
            printf(",%d", eleList[i]);
    }
    printf("]\n");

_exit:
    exit(EXIT_SUCCESS);
}